package com.wudl.core;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

import java.util.Arrays;

/**
 * TODO
 *  两个流进行合并成为一条流 ---数据类型可以不一致
 * @author wudl
 * @version 1.0
 * @date 2020/12/23 16:13
 */
public class TreansformConnect {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> inputDs01 = env.fromCollection(Arrays.asList(1, 2, 5, 6, 7, 9));
        DataStreamSource<String> inputDs02 = env.fromCollection(Arrays.asList("hadoop", "java", "flink"));
        ConnectedStreams<Integer, String> connecteDs = inputDs01.connect(inputDs02);

        DataStream<String> mapDs = connecteDs.map(new CoMapFunction<Integer, String, String>() {
            @Override
            public String map1(Integer value) throws Exception {
                return value+"";
            }

            @Override
            public String map2(String value) throws Exception {
                return value;
            }
        });
        mapDs.print();
        env.execute();

    }
}
